package com.atguigu.gmall;

import com.atguigu.gmall.common.constant.RedisConst;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author: atguigu
 * @create: 2023-08-28 14:33
 */
@Slf4j
@SpringBootApplication //(scanBasePackages = {"com.atguigu.gmall"})
@EnableAsync //开启SpringBoot异步
public class ProductApp implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(ProductApp.class, args);
    }


    @Autowired
    private RedissonClient redissonClient;

    /**
     * springboot应用启动后自动执行一次，该方法执行前IOC容器对象都实例化
     *
     * @param args incoming main method arguments
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        log.info("[商品服务]初始化布隆过滤器到Redis");
        //1.创建布隆过滤器对象
        RBloomFilter<Long> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);

        //2.初始化布隆过滤器
        bloomFilter.tryInit(300000L, 0.03);
    }
}
